﻿@model ShipmentDetailsModel
@using Logistics.Web.Models.Shipment
@using Nop.Core.Domain.Shipping;

<div class="tracking-details-content">

    <div class="section-wrapper">
        <input type="hidden" id="shipment-id" data-url="@Url.Action("Details", "Shipment")" data-name="ShipmentId" , data-value="@Model.Id" data-name2="isOrderDetails" data-value2="true" />
        @if (!string.IsNullOrWhiteSpace(Model.TrackingNumber))
        {
            <div class="package-heading">
                <div class="tracking-status">
                    <div class="row">
                        <div class="col-sm-8">
                            <h4>@T("Order.Shipments.TrackingNumber"): @Model.TrackingNumber</h4>
                        </div>
                        <div class="col-sm-4 tracking-status-status">
                            <p>@T("Order.Shipments.ShipmentStatus"): <span class="@Model.Status">@Model.Status.ToString()</span></p>
                        </div>
                        <div class="clear"></div>

                        @if (Model.ShowDetails && !String.IsNullOrEmpty(Model.PackageAttributes))
                        {
                            <div class="col-sm-4 tracking-status-attributes">@T("Order.Shipments.Attributes"): @Model.PackageAttributes</div>
                        }

                        @if (Model.ShippedDate.HasValue)
                        {
                            <div class="shipped-date col-xs-4">
                                @T("Order.Shipments.ShippedDate"): @Model.ShippedDate.Value.ToString("D")
                            </div>
                        }
                        @if (Model.DeliveryDate.HasValue)
                        {
                            <div class="delivery-date col-xs-4">
                                @T("Order.Shipments.DeliveryDate"): @Model.DeliveryDate.Value.ToString("D")
                            </div>
                        }
                        <div class="clear"></div>
                    </div>
                </div>
                @if (Model.DisplayedEvents != null && Model.DisplayedEvents.Count > 0)
                {
                    <div class="package-status-wrapper">
                        <div class="package-statuses">
                            @foreach (var s in Model.DisplayedEvents)
                            {
                                <div class="displayed-status" data-width="@s.BarWidth">@s.EventName</div>
                            }
                        </div>
                        <div class="progress">
                            <div class="package-status-bar">
                                <div class="progress-bar progress-bar-striped" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100">
                                </div>
                            </div>
                        </div>

                    </div>
                }
            </div>

            <div class="package-details">
                <div class="row">
                    <div class="pickup-address package-detail-section col-ms-6 col-sm-4">
                        @if (Model.ShowDetails)
                        {
                        <h3>@T("Logistics.Order.PickupAddress")</h3>
                        @Html.Partial("_ShipmentAddress", Model.PickupAddress)
                        }
                        else
                        {
                        <h3>Pickup From</h3>
                        <span>@Model.PickupAddress.City, @Model.PickupAddress.StateProvinceName</span>
                        }
                    </div>
                    <div class="shipping-address package-detail-section col-ms-6 col-sm-4">
                        @if (Model.ShowDetails)
                        {
                        <h3>@T("Logistics.Order.DeliveryAddress")</h3>
                        @Html.Partial("_ShipmentAddress", Model.DeliveryAddress)
                        }
                        else
                        {
                        <h3>Deliver To</h3>
                        <span>@Model.DeliveryAddress.City, @Model.DeliveryAddress.StateProvinceName</span>
                        }
                    </div>

                    <div class="shipping-comment package-detail-section col-sm-4">
                        @Html.Partial("_PackageComment", Model)
                    </div>
                    <div class="clear"></div>

                    @*@if (!String.IsNullOrEmpty(Model.PickUpTimeShow))
                    {
                        <div class="pickup-address package-detail-section col-ms-6 col-xs-12">
                            <h3>Estimated Pickup Time</h3>
                            <div>
                                @Model.PickUpTimeShow
                            </div>
                        </div>
                    }*@
                    

                    @if (!String.IsNullOrEmpty(Model.PickupTimeUserSelected))
                    {
                        <div class="pickup-address package-detail-section col-ms-6 col-xs-12">
                            <h3>Estimated Pickup Time</h3>
                            <div>
                                @Model.PickupTimeUserSelected
                            </div>
                        </div>
                    }
                    <div class="clear"></div>
                    <div class="package-history package-detail-section col-xs-12">
                        <h3>@T("Order.Shipments.PackageHistory")</h3>
                        @Html.Partial("_ShipmentEvents", Model)
                    </div>
                    <div class="package-tracking-action package-detail-section col-xs-12">
                        <h3>@T("Order.Shipments.PackageOptions")</h3>
                        @if (Model.ShowDetails)
                        {
                        @Html.ActionLink(T("Admin.Logistics.Printpackagingslip").Text, "DownloadWaybill", "Order", new { id = Model.PackageId, area = "Logistics" }, new { @class = "btn btn-normal", target = "_blank" })

                            if (Model.CanCancel || Model.CanChangePickupAddress || Model.CanChangeDeliveryAddress || Model.CanScheduleDelivery)
                            {
                        @*if (Model.CanScheduleDelivery)
                            {
                                <input type="button" data-url="@Url.Action("ScheduleDelivery", "Shipment")" data-name="PackageId" data-value="@Model.PackageId" class="btn btn-normal" value="@T("Order.Shipments.ScheduleDelivery").Text" />
                                <input type="button" data-url="@Url.Action("WareHousePickUp", "Shipment")" data-name="PackageId" data-value="@Model.PackageId" class="btn btn-normal" value="@T("Logistics.Tracking.WarehousePickUp").Text" />
                            }*@
                                if (Model.CanChangePickupAddress)
                                {
                        <input type="button" data-url="@Url.Action("ChangeAddress", "Shipment")" data-name="packageId" data-value="@Model.PackageId" data-name2="typeId" data-value2="1" class="btn btn-normal" value="@T("Order.Shipments.ChangePickupAddress").Text" />
                                }
                                if (Model.CanChangeDeliveryAddress)
                                {
                        <input type="button" data-url="@Url.Action("ChangeAddress", "Shipment")" data-name="packageId" data-value="@Model.PackageId" data-name2="typeId" data-value2="2" class="btn btn-normal" value="@T("Order.Shipments.ChangeDeliveryAddress").Text" />
                                }
                                if (Model.CanCancel)
                                {
                                    var isFree = Model.IsCancelPackageFree ? "" : " *";
                        <input type="button" data-url="@Url.Action("Cancel", "Shipment", new { shipmentId = Model.Id })" class="btn btn-danger" value="@T("order.shipments.cancel").Text" />
                                }
                        @*if (!Model.IsChangeDeliveryAddressFree || !Model.IsChangePickupAddressFree || !Model.IsScheduleDeliveryFree || !Model.IsCancelPackageFree)
                            {
                                <div>@T("Order.Shipments.ChargeDescription")</div>
                            }*@
                            }
                        }
                        else
                        {
                        <input type="button" data-url="@Url.Action("ShowDetails", "Shipment")" data-name="id" data-value="@Model.Id" class="btn btn-normal" value="@T("Order.Shipments.ShowDetails").Text" />
                        }



                        @*@if (Model.RecentlyViewedShipmentHistory.Count > 0)
                            {
                                <h2>Recently Viewed</h2>
                                <div class="recently-viewed-packages">
                                    @foreach (var s in Model.RecentlyViewedShipmentHistory)
                                    {
                                        <a href="@Url.Action("Details", new { shipmentId = s.ShipmentId })"><div class="recently-viewed"><h4>@s.TrackingNumber</h4><span class="event-type-@s.Type">@s.EventName</span> on @s.LastUpdatedDateTime.ToString()</div></a>
                                    }
                                </div>
                            }*@
                    </div>
                </div>
            </div>
        }
    </div>
</div>


<script type="text/javascript">

    @if (Model.DisplayedStatusType == 1)
    {
        <text>
    $(".package-status-bar .progress-bar").addClass("progress-bar-success");
    </text>
    }
    else if (Model.DisplayedStatusType == 2)
    {
        <text>
    $(".package-status-bar .progress-bar").addClass("progress-bar-info");
    </text>
    }
    else if (Model.DisplayedStatusType == 3)
    {
        <text>
    $(".package-status-bar .progress-bar").addClass("progress-bar-danger");
    </text>
    }
    else if (Model.DisplayedStatusType == 4)
    {
        <text>
    $(".package-status-bar .progress-bar").addClass("progress-bar-warning");
    </text>
    }


    var vcname = "spotshub.trackauth." + "@Model.Id";
    var vaction;
    $(document).ready(function () {
        if ($(".package-statuses").length) {
            var fullbarwidth = 0;
            var barpos = parseInt("@Model.DisplayedEventsBarLocation");
            $(".displayed-status").each(function () {
                fullbarwidth += parseInt($(this).attr("data-width"));
            });
            var p = Math.floor(100 / fullbarwidth);
            var r = 100 % fullbarwidth;
            $(".displayed-status").each(function () {
                var a = 0;
                var i = parseInt($(this).attr("data-width"));
                if (r > 0 && i < r) {
                    a = 1;
                }
                $(this).css("width", p * parseInt($(this).attr("data-width")) + a + "%");
            });
            var a1 = 0;
            if (r > 0 && barpos < r) {
                a1 = 1;
            }
            setTimeout(function () {
                animateBar(barpos * p + a1);
            }, 500);
        }

    });
    function animateBar(value) {
        $(".package-status-bar").stop().animate({
            width: value + "%"
        }, 1200);
    }
</script>
